<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Outsign extends Model
{
    protected $table = "tp_out_sign";

    function mainData($size=10,$where=''){
        $map[] = ['1','=','1'];
        if(input('patient_id') && input('patient_id')<>''){
            $map[] = ['p.patient_id','like','%'.input('patient_id').'%'];
        }
        if(input('patient_name') && input('patient_name')<>''){
            $map[] = ['p.patient_name','like','%'.input('patient_name').'%'];
        }
        if(input('rfid') && input('rfid')<>''){
            $map[] = ['p.rfid','like','%'.input('rfid').'%'];
        }
        if(input('department_code') && input('department_code')<>''){
            $map[] = ['p.department_code','like','%'.input('department_code').'%'];
        }
        if($where <> ''){
            $map = array_merge($where,$map);
        }
        // dump($map);exit;
        $count = $this
                ->alias('o')
                ->join('patient p','p.rfid = o.rfid','left')
                ->where($map)
                 ->count();// 查询满足要求的总记录数
        // echo 1;
        $list = $this
            ->alias('o')
            ->join('patient p','p.rfid = o.rfid','left')
            ->field('p.patient_id,p.patient_name,p.gender,p.age,p.department,p.department_code,p.rfid,o.id,o.starttime,o.endtime')
            ->where($map)
            ->order('o.id desc')
            ->paginate($size,$count,['query'=>request()->param()])
            ->each(function($item,$key){
                return $item;
            });
        $page = $list->render();

        $data['count'] = $count;
        $data['list'] = $list;
        $data['page'] = $page;
        return $data;
    }

}